package com.ruoyi.web.controller.contract;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ContractCounterpart;
import com.ruoyi.system.service.IContractCounterpartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 相对方管理Controller
 *
 * @author ruoyi
 * @date 2024-02-29
 */
@RestController
@RequestMapping("/counterpart")
public class ContractCounterpartController extends BaseController
{
    @Autowired
    private IContractCounterpartService contractCounterpartService;

    /**
     * 查询相对方管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ContractCounterpart contractCounterpart)
    {
        startPage();
        List<ContractCounterpart> list = contractCounterpartService.selectContractCounterpartList(contractCounterpart);
        return getDataTable(list);
    }

    /**
     * 查询所有
     * @param contractCounterpart
     * @return
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(ContractCounterpart contractCounterpart)
    {
        List<ContractCounterpart> list = contractCounterpartService.selectContractCounterpartList(contractCounterpart);
        return AjaxResult.success(list);
    }

    /**
     * 导出相对方管理列表
     */
    @Log(title = "相对方管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContractCounterpart contractCounterpart)
    {
        List<ContractCounterpart> list = contractCounterpartService.selectContractCounterpartList(contractCounterpart);
        ExcelUtil<ContractCounterpart> util = new ExcelUtil<ContractCounterpart>(ContractCounterpart.class);
        util.exportExcel(response, list, "相对方管理数据");
    }

    /**
     * 获取相对方管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(contractCounterpartService.selectContractCounterpartById(id));
    }

    /**
     * 新增相对方管理
     */
    @Log(title = "相对方管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContractCounterpart contractCounterpart)
    {
        return toAjax(contractCounterpartService.insertContractCounterpart(contractCounterpart));
    }

    /**
     * 修改相对方管理
     */
    @Log(title = "相对方管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContractCounterpart contractCounterpart)
    {
        return toAjax(contractCounterpartService.updateContractCounterpart(contractCounterpart));
    }

    /**
     * 删除相对方管理
     */
    @Log(title = "相对方管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(contractCounterpartService.deleteContractCounterpartByIds(ids));
    }
}
